from typing import List


class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def levelOrder(self, root: TreeNode) -> List[List[int]]:
        if root is None:
            return []

        res = []


        def dfs (root:TreeNode, level:int):
            if len(res)<=level:
                res.append([])
            res[level].append(root.val)
            if root.left:dfs(root.left, level+1)
            if root.right:dfs(root.right, level+1)
        dfs(root, 0)
        return res
        